/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Logica;

import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 *
 * @author Fernando
 */
public class Estrategia implements Serializable {

    private String nombre;
    private boolean tipo;
    private String rman;
    private boolean status;
    private String horario;
    private String server;

    public Estrategia() {
        this.nombre = "";
        this.tipo = false;
        this.rman = "";
        this.status = false;
        this.horario = "";
        this.server = "";
    }

    public Estrategia(String n, boolean t, String r, boolean s, String h, String ser) {
        this.nombre = n;
        this.tipo = t;
        this.rman = r;
        this.status = s;
        this.horario = h;
        this.server = ser;
    }

    public String getNombre() {
        return nombre;
    }

    public void setNombre(String nombre) {
        this.nombre = nombre;
    }

    public boolean isTipo() {
        return tipo;
    }

    public void setTipo(boolean tipo) {
        this.tipo = tipo;
    }

    public String getRman() {
        return rman;
    }

    public void setRman(String rman) {
        this.rman = rman;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public String getHorario() {
        return horario;
    }

    public void setHorario(String horario) {
        this.horario = horario;
    }

    @Override
    public String toString() {
        String type="";
        String act="";
        
        if(this.tipo){
            type="FULL";
        }else{
            type="INCREMENTAL";
        }
        
        if(this.status){
            act="ACTIVE";
        }else{
            act="INACTIVE";
        }
        StringBuilder s = new StringBuilder();
        s.append(String.format(this.nombre + "\n"));    
        s.append(String.format(type + "\n"));
        s.append(String.format(this.rman + "\n"));
        s.append(String.format(act + "\n"));
        s.append(String.format(this.horario + "\n"));
        s.append(String.format(this.server + "\n"));
        return s.toString();
    }

    public boolean guardar(String arch) {
        try {
            FileOutputStream fileOut = new FileOutputStream(arch, true);
            ObjectOutputStream out = new ObjectOutputStream(fileOut);
            out.writeObject(this);
            out.close();
            fileOut.close();
        } catch (IOException i) {
            i.printStackTrace();
            return false;
        }

        return true;
    }

    public Estrategia cargar(String arch) {
        Estrategia obj;
        try {
            FileInputStream fis = new FileInputStream(arch);
            ObjectInputStream ois = new ObjectInputStream(fis);

            obj = (Estrategia) ois.readObject();

            ois.close();
            fis.close();
            System.out.print("CARGA");
        } catch (IOException e) {
            //e.printStackTrace();
            return null;
        } catch (ClassNotFoundException e) {
            //e.printStackTrace();
            return null;
        }

        return obj;
    }

    
    public String getServer() {
        return server;
    }

    
    public void setServer(String server) {
        this.server = server;
    }
}
